<?php
	class HTMLTag {
		var $attributes;
		var $name;
		var $content;
		function HTMLTag($name="span",$attributes=array(),$content=NULL){
			$this->name = $name;
			$this->content = $content;
			$this->attributes = $attributes;
		}
		function buildAttributes(){
			$attributesResult = "";
			foreach($this->attributes as $key => $value){
				if($key == "id"){
					$modseparator = strpos($value,":");
					if($modseparator!==FALSE) $value = substr($value,0,$modseparator);
				}
				$attributesResult .= " ".$key."=\"".$value."\"";
			}
			return $attributesResult;
		}
		function build(){
			$result = "";
			$result .= "<".$this->name;
			$result .= $this->buildAttributes();
			if($this->content!==NULL){
				$result .= ">";
				$result .= $this->content;
				$result .= "</".$this->name;
			}else{
				$result .= " /";	
			}
			$result .= ">";
			return $result;
		}
	}
	function simple_tag($name,$content=NULL,$options=array()){
		$simple = new HTMLTag($name,$options,$content);
		return $simple->build();
	}
	function image_tag($src,$options=array()){
		if(APP_IMAGES_FOLDER){
			$options["src"] = APP_ROOT.APP_IMAGES_FOLDER.$src;
		}else{
			$options["src"] = $src;
		}
		$options["border"] = 0;
		$img = new HTMLTag("img",$options);
		return $img->build();
	}
	
	function mail_tag($src,$options=array()){
		return link_tag($src,"mailto:".$src,$option);
	}
	function link_tag($name,$src,$options=array()){
		$options["href"] = $src;
		$link = new HTMLTag("a",$options,$name);
		return $link->build(); 
	}
	function div_tag($content,$options=array()){
		return simple_tag("div",$content,$options);
	}
	function br_tag(){
		return simple_tag("br");
	}
	function span_tag($content,$options){
		return simple_tag("span",$content,$options);
	}
	function nbsp(){
		return "&nbsp;";
	}
	/**
	FORMS HTMLTags
	**/
	function form_tag($name,$content,$options=array()){
		if(!array_key_exists("id",$options)) $options["id"] = $name;
		$options["name"] = $name;
		$select = new HTMLTag("form",$options,$content);
		return $select->build();
	}
	
	function select_tag($name,$content,$options=array()){
		if(!array_key_exists("id",$options)) $options["id"] = $name;
		$options["name"] = $name;
		$select = new HTMLTag("select",$options,$content);
		return $select->build();
	}
	
	
	function radio_tag($name,$value,$checked=FALSE,$options=array()){
		$options["type"] = "radio";
		if(!array_key_exists("id",$options)) $options["id"] = $name;
		$options["name"] = $name;
		$options["value"] = $value;
		if($checked) $options["checked"] = "checked";
		$radio = new HTMLTag("input",$options);
		return $radio->build();
	}
	
	function check_tag($name,$value,$checked=FALSE,$options=array()){
		$options["type"] = "checkbox";
		if(!array_key_exists("id",$options)) $options["id"] = $name;
		$options["name"] = $name;
		$options["value"] = $value;
		if($checked) $options["checked"] = "checked";
		$check = new HTMLTag("input",$options);
		return $check->build();
	}
	
	function option_tag($name,$value,$selected=false){
		$options = array();
		$options["value"] = $value;
		if($selected) $options["selected"] = "selected";
		$option = new HTMLTag("option",$options,$name);
		return $option->build();
	}
	function submit_tag($name,$options=array()){
		$options["type"] = "submit";
		$options["value"] = $name;
		$submit = new HTMLTag("input",$options);
		return $submit->build();
	}
	function hidden_tag($name,$value,$options=array()){
		$options["type"] = "hidden";
		if(!array_key_exists("id",$options)) $options["id"] = $name;
		$options["name"] = $name;
		$options["value"] = $value;
		$hidden = new HTMLTag("input",$options);
		return $hidden->build();
	}
	
	function password_tag($name,$value,$options=array()){
		$options["type"] = "password";
		if(!array_key_exists("id",$options)) $options["id"] = $name;
		$options["name"] = $name;
		$options["value"] = $value;
		$text = new HTMLTag("input",$options);
		return $text->build();
	}
	
	function textfield_tag($name,$value,$options=array()){
		$options["type"] = "text";
		if(!array_key_exists("id",$options)) $options["id"] = $name;
		$options["name"] = $name;
		$options["value"] = $value;
		$text = new HTMLTag("input",$options);
		return $text->build();
	}
	
	function filefield_tag($name,$options=array()){
		$options["type"] = "file";
		if(!array_key_exists("id",$options)) $options["id"] = $name;
		$options["name"] = $name;
		$text = new HTMLTag("input",$options);
		return $text->build();
	}
	
	function textarea_tag($name,$value,$options=array()){
		if(!array_key_exists("id",$options)) $options["id"] = $name;
		$options["name"] = $name;
		$text = new HTMLTag("textarea",$options,$value);
		return $text->build();
	}
?>
